namespace ClassyBlog.DomainObjects.Specs.Unit
{
    using System;
    using System.Collections.Generic;

    using Machine.Specifications;

    [Subject(typeof(Post))]
    public class when_post_is_created
    {
        static Post post;

        Because of = () => post = new Post();

        It should_have_id = () => post.Id.ShouldNotEqual(Guid.Empty);

        It should_allow_comments = () => post.AllowComments.ShouldBeTrue();

        It should_have_empty_tags = () => post.Tags.ShouldBeEmpty();
    }

    [Subject(typeof(Post))]
    public class when_post_id_is_set
    {
        static Post post;
        static Guid id;

        Establish context = () =>
        {
            post = new Post();
            id = Guid.NewGuid();
        };

        Because of = () => post.Id = id;

        It should_return_the_same = () => post.Id.ShouldEqual(id);
    }

    [Subject(typeof(Post))]
    public class when_setting_dynamic_property_of_post
    {
        static Post post;
        static dynamic dynamicPost;

        static string property;

        Establish context = () =>
        {
            post = new Post();
            dynamicPost = post;
            dynamicPost.DummyProperty = "DynamicValue";
        };

        Because of = () => property = dynamicPost.DummyProperty;

        It should_be_able_to_get = () => property.ShouldEqual("DynamicValue");
    }

    [Subject(typeof(Post))]
    public class when_getting_regular_property_as_dynamic_property_of_post
    {
        static Post post;
        static dynamic dynamicPost;

        static string title;

        Establish context = () =>
        {
            post = new Post { Title = "Hello world" };
            dynamicPost = post;
        };

        Because of = () => title = dynamicPost.Title;

        It should_be_able_to_get = () => title.ShouldEqual("Hello world");
    }

    [Subject(typeof(Post))]
    public class when_setting_regular_property_as_dynamic_property_of_post
    {
        static Post post;
        static dynamic dynamicPost;

        Establish context = () =>
        {
            post = new Post();
            dynamicPost = post;
        };

        Because of = () => dynamicPost.Title = "Hello world";

        It should_be_able_to_set = () => post.Title.ShouldEqual("Hello world");
    }

    [Subject(typeof(Post))]
    public class when_post_dynamic_property_names_is_accessed
    {
        static Post post;
        static IEnumerable<string> dynamicPropertyNames;

        Establish context = () =>
        {
            post = new Post();
            post.SetDynamicProperty("foo", "bar");
        };

        Because of = () => dynamicPropertyNames = post.DynamicPropertyNames;

        It should_return_from_dynamic_property = () =>
            dynamicPropertyNames.ShouldContain("foo");
    }
}